package com.ruoyi.base.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.base.domain.BaseBuilding;
import com.ruoyi.base.service.IBaseBuildingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼宇Controller
 * 
 * @author yepanpan
 * @date 2020-11-09
 */
@Api("楼宇信息管理")
@RestController
@RequestMapping("/base/building")
public class BaseBuildingController extends BaseController
{
    @Autowired
    private IBaseBuildingService baseBuildingService;

    /**
     * 查询楼宇列表
     */
    @ApiOperation("获取楼宇列表")
    @PreAuthorize("@ss.hasPermi('base:building:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseBuilding baseBuilding)
    {
        startPage();
        List<BaseBuilding> list = baseBuildingService.selectBaseBuildingList(baseBuilding);
        return getDataTable(list);
    }
    
    /**
     * 查询楼宇下拉列表
     */
    @ApiOperation("获取楼宇下拉列表")
    @GetMapping("select")
    public TableDataInfo select(BaseBuilding baseBuilding)
    {
        List<BaseBuilding> list = baseBuildingService.selectBaseBuildingList(baseBuilding);
        return getDataTable(list);
    }

    /**
     * 导出楼宇列表
     */
    @ApiOperation("导出楼宇列表")
    @PreAuthorize("@ss.hasPermi('base:building:export')")
    @Log(title = "楼宇", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseBuilding baseBuilding)
    {
        List<BaseBuilding> list = baseBuildingService.selectBaseBuildingList(baseBuilding);
        ExcelUtil<BaseBuilding> util = new ExcelUtil<BaseBuilding>(BaseBuilding.class);
        return util.exportExcel(list, "building");
    }

    /**
     * 获取楼宇详细信息
     */
    @ApiOperation("获取楼宇详细信息")
    @ApiImplicitParam(name = "id", value = "楼宇ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:building:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseBuildingService.selectBaseBuildingById(id));
    }

    /**
     * 新增楼宇
     */
    @ApiOperation("新增楼宇")
    @PreAuthorize("@ss.hasPermi('base:building:add')")
    @Log(title = "楼宇", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseBuilding baseBuilding)
    {
        return toAjax(baseBuildingService.insertBaseBuilding(baseBuilding));
    }

    /**
     * 修改楼宇
     */
    @ApiOperation("修改楼宇")
    @PreAuthorize("@ss.hasPermi('base:building:edit')")
    @Log(title = "楼宇", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseBuilding baseBuilding)
    {
        return toAjax(baseBuildingService.updateBaseBuilding(baseBuilding));
    }

    /**
     * 删除楼宇
     */
    @ApiOperation("删除楼宇")
    @ApiImplicitParam(name = "id", value = "楼宇ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:building:remove')")
    @Log(title = "楼宇", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseBuildingService.deleteBaseBuildingByIds(ids));
    }
}
